package com.xhwl.logistics.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum VehicleParkingLotSyncHandlerEnum {

    VEHICLE_PARKINGLOT_NOTHING(-1, "vehicleParkingLotNothingSyncHandlerImpl"),
    VEHICLE_PARKINGLOT_KETOP(3, "vehicleParkingLotKeTopSyncHandlerImpl"),
    VEHICLE_PARKINGLOT_NANTOU(26, "vehicleParkingLotNanTouSyncHandlerImpl");

    private final Integer productId;

    private final String syncHandlerName;

    private static final Map<Integer, VehicleParkingLotSyncHandlerEnum> map;
    static {
        map = new HashMap<>();
        for (VehicleParkingLotSyncHandlerEnum vehicleParkingLotSyncHandlerEnum : VehicleParkingLotSyncHandlerEnum.values()) {
            map.put(vehicleParkingLotSyncHandlerEnum.getProductId(), vehicleParkingLotSyncHandlerEnum);
        }
    }

    /**
     * 由于使用了动态生成枚举类的方法，所以不能使用Static代码块生成的map集合
     * @param productId
     * @return
     */
    public static VehicleParkingLotSyncHandlerEnum toVehicleParkingLotSyncHandlerEnum(Integer productId) {
        for (VehicleParkingLotSyncHandlerEnum vehicleParkingLotSyncHandlerEnum : VehicleParkingLotSyncHandlerEnum.values()) {
            if (StringUtils.equals(vehicleParkingLotSyncHandlerEnum.getProductId().toString(),productId.toString())) {
                return vehicleParkingLotSyncHandlerEnum;
            }
        }
//        throw new IllegalArgumentException("非法的VehicleParkingLotHandlerEnum的productId，无法映射到对应的厂商");
        return VEHICLE_PARKINGLOT_NOTHING;
    }

}
